//
//  YMSNavBarBtn.swift
//  YMSWeibo
//
//  Created by 杨茂盛 on 2016/11/12.
//  Copyright © 2016年 杨茂盛. All rights reserved.
//

//给UIBarbuttonItem扩展构造方法
import UIKit

extension UIBarButtonItem{

    //MARK:分类中不能够声明指定的构造器 要使用便利构造
    convenience init(title:String = "",imageName:String,target: Any?, action: Selector?) {
        //设置导航栏右边的按钮
        let rightBtn = UIButton()
        rightBtn.setTitle(title, for: .normal)
        //设置文字颜色
        rightBtn.setTitleColor(UIColor.darkGray, for: .normal)
        rightBtn.setTitleColor(UIColor.orange, for: .highlighted)
        rightBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        rightBtn .setImage(UIImage(named:imageName), for: .normal)
        rightBtn .setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
        //给按钮添加监听事件
        if let ac = action{
            rightBtn.addTarget(target, action: ac, for: .touchUpInside)
        }
        rightBtn.sizeToFit()
        self.init()
        self.customView = rightBtn
    }
}

